********************************************************************************
// South-South migration: the impact of the Venezuelan diaspora on Colombian  //
//                      natives' wages and hours worked                       //
//                          Applied Economics Letters                         //
//                    Mora, Cuadros-Menaca, and Sayago (2022)                 //
********************************************************************************

global d_user  "Your Directory"
cd  "Your Directory"

//Wages Analysis By city

foreach i in 54 47 44 20 13 11 8 5 76{
use "$d_user/Working_Data.dta",clear
gen qdate=yq(Year,trim)
format qdate %tq 	
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
keep if (AREA==15 | AREA==17 | AREA==18 | AREA==19 | AREA==23 | AREA==27 | AREA==41 |AREA==50 |AREA==52 | AREA==63 |AREA==66 |AREA==68 |AREA==70 |AREA==73 |AREA==`i')
synth_runner LWages $controls LWages LWages(`=tq(2017q4)'), trunit(`i') trperiod(`=tq(2018q1)') nested gen_vars
*ereturn list
single_treatment_graphs, trlinediff(-1) effects_ylabels(-30(10)30)
effect_graphs, trlinediff(-1)
graph save "tc" "$d_user\SC`i'.gph", replace
}

graph combine "$d_user\SC5.gph" "$d_user\SC8.gph" "$d_user\SC11.gph" "$d_user\SC13.gph" "$d_user\SC20.gph" "$d_user\SC44.gph" "$d_user\SC47.gph" "$d_user\SC54.gph" "$d_user\SC76.gph"

graph export Figure_2.tif, width(300)

//National Level Wage Effects 

use "$d_user/Working_Data.dta",clear
gen qdate=yq(Year,trim)
format qdate %tq 
generate byte D = (AREA==76 & qdate>=`=tq(2018q1)') | (AREA==54 & qdate>=`=tq(2018q1)') | (AREA==47 & qdate>=`=tq(2018q1)') | ///
                  (AREA==44 & qdate>=`=tq(2018q1)') | (AREA==20 & qdate>=`=tq(2018q1)') | (AREA==13 & qdate>=`=tq(2018q1)') | ///
				  (AREA==11 & qdate>=`=tq(2018q1)') | (AREA==8 & qdate>=`=tq(2018q1)')  | (AREA==5 & qdate>=`=tq(2018q1)')
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate

synth_runner  LWages $controls LWages LWages(`=tq(2017q4)'), d(D) nested
effect_graphs

//Working Hours by city

use "$d_user/Working_Data.dta",clear
merge 1:1 AREA Year trim using "$d_user/Hours.dta"
keep if _m==3
drop _m
save "$d_user\WDHours.dta"

foreach i in 54 47 44 20 13 11 8 5 76{
use "$d_user/WDHours.dta",clear
gen qdate=yq(Year,trim)
format qdate %tq 	
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
keep if (AREA==15 | AREA==17 | AREA==18 | AREA==19 | AREA==23 | AREA==27 | AREA==41 |AREA==50 |AREA==52 | AREA==63 |AREA==66 |AREA==68 |AREA==70 |AREA==73 |AREA==`i')
synth_runner htra $controls htra(`=tq(2016q1)') htra htra(`=tq(2017q1)') htra(`=tq(2017q4)'), trunit(`i') trperiod(`=tq(2018q1)') nested gen_vars
*ereturn list
single_treatment_graphs, trlinediff(-1) effects_ylabels(-30(10)30)
effect_graphs, trlinediff(-1)
graph save "tc" "$d_user\OtherHoursSC`i'.gph", replace
}

//Working Hours National

use "$d_user\WDHours.dta", clear

gen qdate=yq(Year,trim)
format qdate %tq 
generate byte D = (AREA==76 & qdate>=`=tq(2018q1)') | (AREA==54 & qdate>=`=tq(2018q1)') | (AREA==47 & qdate>=`=tq(2018q1)') | ///
                  (AREA==44 & qdate>=`=tq(2018q1)') | (AREA==20 & qdate>=`=tq(2018q1)') | (AREA==13 & qdate>=`=tq(2018q1)') | ///
				  (AREA==11 & qdate>=`=tq(2018q1)') | (AREA==8 & qdate>=`=tq(2018q1)')  | (AREA==5 & qdate>=`=tq(2018q1)')
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate

synth_runner htra $controls htra(`=tq(2016q1)') htra  htra(`=tq(2017q1)') htra(`=tq(2017q4)'), d(D) nested 
effect_graphs


//National Average Effects by City Size

*Wages

use "$d_user/Working_Data.dta",clear
gen qdate=yq(Year,trim)
format qdate %tq 
drop if (AREA==76 | AREA==11 |AREA==8 |AREA==5) 
generate byte D = (AREA==54 & qdate>=`=tq(2018q1)') | (AREA==47 & qdate>=`=tq(2018q1)') | ///
                  (AREA==44 & qdate>=`=tq(2018q1)') | (AREA==20 & qdate>=`=tq(2018q1)') | (AREA==13 & qdate>=`=tq(2018q1)') 			  
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
synth_runner  LWages $controls LWages LWages(`=tq(2017q4)'), d(D) nested
effect_graphs

use "$d_user/Working_Data.dta",clear
gen qdate=yq(Year,trim)
format qdate %tq 
drop if (AREA==54 | AREA==44 |AREA==47 |AREA==20 |AREA==13) 
generate byte D = (AREA==76 & qdate>=`=tq(2018q1)') | (AREA==11 & qdate>=`=tq(2018q1)') | (AREA==8 & qdate>=`=tq(2018q1)')  | (AREA==5 & qdate>=`=tq(2018q1)')
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
synth_runner  LWages $controls LWages LWages(`=tq(2017q4)'), d(D) nested
effect_graphs

*Worked Hours

use "$d_user\WDHours.dta", clear
gen qdate=yq(Year,trim)
format qdate %tq 
drop if (AREA==76 | AREA==11 |AREA==8 |AREA==5) 
generate byte D = (AREA==54 & qdate>=`=tq(2018q1)') | (AREA==47 & qdate>=`=tq(2018q1)') | ///
                  (AREA==44 & qdate>=`=tq(2018q1)') | (AREA==20 & qdate>=`=tq(2018q1)') | (AREA==13 & qdate>=`=tq(2018q1)') 
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
synth_runner htra $controls htra(`=tq(2016q1)') htra  htra(`=tq(2017q1)') htra(`=tq(2017q4)'), d(D) nested 
effect_graphs

use "$d_user\WDHours.dta", clear
gen qdate=yq(Year,trim)
format qdate %tq 
drop if (AREA==54 | AREA==44 |AREA==47 |AREA==20 |AREA==13) 
generate byte D = (AREA==76 & qdate>=`=tq(2018q1)') | (AREA==11 & qdate>=`=tq(2018q1)') | (AREA==8 & qdate>=`=tq(2018q1)')  | (AREA==5 & qdate>=`=tq(2018q1)')
global controls proBachOcup propVenOcup5 tinfoD
tsset AREA qdate
synth_runner htra $controls htra(`=tq(2016q1)') htra  htra(`=tq(2017q1)') htra(`=tq(2017q4)'), d(D) nested 
effect_graphs
